package com.hqyj.project.controller;

import com.hqyj.project.entity.Time;
import com.hqyj.project.entity.Work;
import com.hqyj.project.service.WorkService;
import com.hqyj.project.utils.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Controller
@RequestMapping("/work")
@Slf4j
public class WorkController {

    @Autowired
    public WorkService workService;

    @GetMapping("/select")
    @ResponseBody
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)
    public CommonResult selectInfo(){
        return workService.selectInfo();
    }

    @PostMapping("/updatetime")
    @ResponseBody
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult updateInfo(@RequestBody Work work){
        String mw = work.getWorkMWork().toString().substring(11, 16);
        String mq = work.getWorkMQuit().toString().substring(11, 16);
        String aw = work.getWorkAWork().toString().substring(11, 16);
        String aq = work.getWorkAQuit().toString().substring(11, 16);
        Time time = new Time();
        time.setTimeMw(mw);
        time.setTimeMq(mq);
        time.setTimeAw(aw);
        time.setTimeAq(aq);
        return workService.updateInfo(time);
    }
}
